package org.qfbl.nio;

import java.net.InetSocketAddress;
import java.nio.ByteBuffer;
import java.nio.channels.SocketChannel;

public class NIOClent {
    public static void main(String[] args) throws Exception {
        SocketChannel socketChannel = SocketChannel.open() ;
        socketChannel.configureBlocking(false) ;
        InetSocketAddress inetSocketAddress = new InetSocketAddress("localhost",6666);
        if(!socketChannel.connect(inetSocketAddress)){
            while (!socketChannel.finishConnect()){
                System.out.println("因为连接需要时间，客户端不会阻塞，可以做其他工作");
                Thread.sleep(1000);
            }
        }
        String str = "hello,feng";
        ByteBuffer buffer = ByteBuffer.wrap(str.getBytes());
        socketChannel.write(buffer);
        System.in.read();
    }
}
